# MAC = 1
RELEASE = 1
CC = g++

ifdef RELEASE
CFLAGS    += -Wall -O3
else
#CFLAGS    += -Wall -ggdb -fno-inline -DLOCAL_DEBUG_ENABLED
CFLGAS += -std=c++0x -g
BINDIR = ../dbg
endif

ifdef MAC
CFLAGS += -I/opt/local/include/
endif

LFLAGS += -Wall -lpthread -L../../polarssl-1.2.3/library -lpolarssl

ifdef MAC
LFLAGS += -L/opt/local/lib
CFLAGS += -D__MAC_OSX__
else
LFLAGS += -lrt
endif

INCLUDES  = -I.
ifndef CC
CC = g++44
endif

OBJDIR  = ../obj
BINDIR  = ../bin

all: dirs $(BINDIR)/zest $(BINDIR)/virtualized

test: all $(BINDIR)/testcontent

coll: $(BINDIR)/collider


.PHONY: dirs clean

################################################################################
################################################################################

$(BINDIR)/collider: collider.c
	gcc collider.c -lquadmath -lm -o $(BINDIR)/collider

################################################################################
################################################################################

$(BINDIR)/zest: $(OBJDIR)/zest.o $(OBJDIR)/BaseDedup.o $(OBJDIR)/AccuDedup.o $(OBJDIR)/FastDedup.o $(OBJDIR)/IndexedSet.o $(OBJDIR)/DRAMImageStream.o $(OBJDIR)/memline.o $(OBJDIR)/Timer.o
	$(CC) -o $(BINDIR)/zest $(OBJDIR)/zest.o $(OBJDIR)/BaseDedup.o $(OBJDIR)/AccuDedup.o $(OBJDIR)/FastDedup.o $(OBJDIR)/IndexedSet.o $(OBJDIR)/DRAMImageStream.o $(OBJDIR)/memline.o $(OBJDIR)/Timer.o $(LFLAGS)

$(BINDIR)/testcontent: $(OBJDIR)/testcontent.o $(OBJDIR)/memline.o randvals.hpp memline.hpp
	$(CC) -o $(BINDIR)/testcontent $(OBJDIR)/testcontent.o $(OBJDIR)/memline.o $(LFLAGS)

$(BINDIR)/virtualized: virtualized.cpp
	$(CC) virtualized.cpp -o $(BINDIR)/virtualized

$(OBJDIR)/memline.o: memline.cpp memline.hpp Makefile
	$(CC) $(CFLAGS) $(INCLUDES) -c memline.cpp -o $(OBJDIR)/memline.o

$(OBJDIR)/AccuDedup.o: AccuDedup.cpp AccuDedup.hpp Makefile
	$(CC) $(CFLAGS) $(INCLUDES) -c AccuDedup.cpp -o $(OBJDIR)/AccuDedup.o

$(OBJDIR)/BaseDedup.o: BaseDedup.cpp BaseDedup.hpp IndexedSet.hpp Makefile
	$(CC) $(CFLAGS) $(INCLUDES) -c BaseDedup.cpp -o $(OBJDIR)/BaseDedup.o

$(OBJDIR)/FastDedup.o: FastDedup.cpp FastDedup.hpp Makefile
	$(CC) $(CFLAGS) $(INCLUDES) -c FastDedup.cpp -o $(OBJDIR)/FastDedup.o

$(OBJDIR)/IndexedSet.o: IndexedSet.cpp IndexedSet.hpp Makefile
	$(CC) $(CFLAGS) $(INCLUDES) -c IndexedSet.cpp -o $(OBJDIR)/IndexedSet.o

$(OBJDIR)/Timer.o: Timer.cpp Timer.hpp Makefile
	$(CC) $(CFLAGS) $(INCLUDES) -c Timer.cpp -o $(OBJDIR)/Timer.o

$(OBJDIR)/DRAMImageStream.o: DRAMImageStream.cpp DRAMImageStream.hpp Makefile
	$(CC) $(CFLAGS) $(INCLUDES) -c DRAMImageStream.cpp -o $(OBJDIR)/DRAMImageStream.o

$(OBJDIR)/zest.o: zest.cpp HashFunctions.hpp PrettyPrints.hpp Makefile
	$(CC) $(CFLAGS) $(INCLUDES) -c zest.cpp -o $(OBJDIR)/zest.o

$(OBJDIR)/testcontent.o: testcontent.cpp HashFunctions.hpp PrettyPrints.hpp Makefile
	$(CC) $(CFLAGS) $(INCLUDES) -c testcontent.cpp -o $(OBJDIR)/testcontent.o

dirs:
	mkdir -p $(BINDIR)
	mkdir -p $(OBJDIR)

clean:
	\rm -f $(OBJDIR)/*
	\rm -f $(BINDIR)/*
